-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refact(core): optimized batch removal of remaining indices consumed by a single consumer #2203
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2203 +/- ##
============================================
+ Coverage 64.39% 68.58% +4.18%
- Complexity 678 979 +301
============================================
Files 497 498 +1
Lines 40573 40681 +108
Branches 5663 5681 +18
============================================
+ Hits 26129 27902 +1773
+ Misses 11828 10074 -1754
- Partials 2616 2705 +89
... and 76 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
53d99a1
to
8441b2a
Compare
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Fixed
Show fixed
Hide fixed
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Fixed
Show fixed
Hide fixed
if (this.state.compareAndSet(State.INIT, State.EXECUTE)) { | ||
try { | ||
RemoveLeftIndexJob job = new RemoveLeftIndexJob(pendingQueue, this::consumeComplete, | ||
this::reSchedule); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just call reSchedule() in consumeComplete()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, the reSchedule method is to start the job execution when it detects that there is data. The consumeComplete function means that the current job has been completed and the mark needs to be updated. The next time new data enters the queue, the job can be triggered
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review it soon:)
raft api test error: [INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.apache.hugegraph.api.ApiTestSuite
Error: Tests run: 90, Failures: 1, Errors: 0, Skipped: 1, Time elapsed: 714.611 s <<< FAILURE! - in org.apache.hugegraph.api.ApiTestSuite
Error: testTruncate(org.apache.hugegraph.api.GremlinApiTest) Time elapsed: 1.257 s <<< FAILURE!
java.lang.AssertionError: Response with status 500 and content {"exception":"java.lang.IllegalStateException","message":"The snapshot future can't be null","cause":"[java.lang.IllegalStateException]"} expected:<200> but was:<500>
at org.apache.hugegraph.api.GremlinApiTest.testTruncate(GremlinApiTest.java:139)
[INFO]
[INFO] Results:
[INFO]
Error: Failures:
Error: GremlinApiTest.testTruncate:139->BaseApiTest.assertResponseStatus:615 Response with status 500 and content {"exception":"java.lang.IllegalStateException","message":"The snapshot future can't be null","cause":"[java.lang.IllegalStateException]"} expected:<200> but was:<500>
[INFO]
Error: Tests run: 90, Failures: 1, Errors: 0, Skipped: 1 |
the code future.complete(Status.OK(), () -> null); return a null future, Maybe be the place should put a future that complete with null value |
java 11 rocksdb block |
2e76d4b
to
16f6934
Compare
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskCallable.java
Outdated
Show resolved
Hide resolved
@@ -145,7 +145,7 @@ public static void decompressTar(String sourceFile, String outputDir, | |||
Files.createDirectories(newPath); | |||
} else { | |||
// check parent folder again | |||
Path parent = newPath.getParent(); | |||
Path parent = newPath.toAbsolutePath().getParent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we split into a separated commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly did it for convenience, putting two git commits together is simpler.
hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskCallable.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
return ret; | ||
} | ||
|
||
private Object executeBatchJob(List<EphemeralJob<?>> jobs, Object prev) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can keep List<Job<?>>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose of the queue is to batch EphemeralJob. The name EphemeralJob is preferred and the job's parameters must be set during initialization (the SysTaskCallable defines the params method).
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/raft/rpc/RpcForwarder.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/EphemeralJobQueue.java
Outdated
Show resolved
Hide resolved
if (e instanceof InterruptedException) { | ||
Thread.currentThread().interrupt(); | ||
if (queue != null) { | ||
queue.queue().clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why called clear() here.
and prefer to call queue.clear()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an InterruptedException occurs, these tasks may be aborted, so clear all tasks
hugegraph-core/src/main/java/org/apache/hugegraph/security/HugeSecurityManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskCallable.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/task/EphemeralJobQueue.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/task/EphemeralJobQueue.java
Show resolved
Hide resolved
.job(job) | ||
.schedule(); | ||
return task.id(); | ||
job.selfCommit(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does only RemoveLeftIndexJob class contain the selfCommit()
method? if not then we can move selfCommit() call into submitEphemeralJob().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should handle everything in batches to keep it simple. Let's exclude 'selfCommit' for now.
|
||
private static final long PAGE_SIZE = Query.COMMIT_BATCH; | ||
private static final String BATCH_EPHEMERAL_JOB = "batch-ephemeral-job"; | ||
private static final int MAX_CONSUME_COUNT = EphemeralJobQueue.CAPACITY / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now COMMIT_BATCH is 100, CAPACITY is 1000.
should we let CAPACITY >> COMMIT_BATCH and MAX_CONSUME_COUNT ~= PAGE_SIZE?
such as let MAX_CONSUME_COUNT = COMMIT_BATCH, let CAPACITY = 100 * COMMIT_BATCH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean remove "PAGE_SIZE" field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change to below formula:
CAPACITY = 100 * Query.COMMIT_BATCH;
PAGE_SIZE = Query.COMMIT_BATCH;
MAX_CONSUME_COUNT = 2 * PAGE_SIZE;
hugegraph-core/src/main/java/org/apache/hugegraph/task/EphemeralJobQueue.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/task/EphemeralJobQueue.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/IndexableTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/SchemaTransaction.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphIndexTransaction.java
Outdated
Show resolved
Hide resolved
@@ -1780,7 +1776,6 @@ protected long removeIndexLeft(ConditionQuery query, | |||
// Process secondary index or search index | |||
sCount += this.processSecondaryOrSearchIndexLeft(cq, element); | |||
} | |||
this.tx.commit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we don't support auto commit anymore?
// This code forwards the request to the Raft leader and considers the operation successful | ||
// if it's forwarded successfully. It returns a RaftClosure because the calling | ||
// logic expects a RaftClosure result. Specifically, if the current instance is the Raft leader, | ||
// it executes the corresponding logic locally and notifies the calling logic asynchronously | ||
// via RaftClosure. Therefore, the result is returned as a RaftClosure here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better to use /* */
next time
No description provided.